//
//  ViewController.m
//  下拉加载
//
//  Created by apple on 16/12/15.
//  Copyright © 2016年 LWB. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tbview;
@property(nonatomic,strong)NSMutableArray *arr;
@property(nonatomic,strong)NSTimer *myTimer;
@end

@implementation ViewController
-(NSMutableArray *)arr{
    if (_arr==nil) {
        _arr = [NSMutableArray arrayWithObjects:@"A",@"B",@"C",@"D", nil];
    }else{
        [_arr addObjectsFromArray:@[@"A",@"B",@"C",@"D"]];
    }
    return _arr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _tbview = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _arr = self.arr;
    _tbview.delegate = self;
    _tbview.dataSource = self;
    [self.view addSubview:_tbview];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"%lu",_arr.count+1);
    return _arr.count+1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    if (indexPath.row<_arr.count) {
        cell.textLabel.text = _arr[indexPath.row];
    }else{
        UIActivityIndicatorView *myActivit = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(45, 0, 40, 40)];
        myActivit.backgroundColor = [UIColor blackColor];
        [cell.contentView addSubview:myActivit];
        [myActivit startAnimating];
        _myTimer =[NSTimer scheduledTimerWithTimeInterval:1.5
                                                   target:self selector:@selector(action) userInfo:nil repeats:NO];
       [_myTimer setFireDate:[NSDate distantPast]];
//        [UIView animateWithDuration:1 animations:^{
//            _arr =self.arr;
//            [_tbview reloadData];
//  
//        }];
        
    }
    return cell;
}
-(void)action{
    _arr =self.arr;
   [_tbview reloadData];
   [_myTimer setFireDate:[NSDate distantFuture]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
